﻿using System;
using System.Collections.Generic;
using System.Text;

using Torch.WL.DataAccess.CleanChina;
using Torch.WL.Entity.CleanChina;
using Torch.FrameWork.Utility;

namespace Torch.WL.Business.CleanChina
{
    class TbEMManager
    {
        private readonly TbEMAccess dal = new TbEMAccess();

        private static TbEMManager _emManager;
        public static TbEMManager Instance()
        {
            if (null == _emManager)
                _emManager = new TbEMManager();

            return _emManager;
        }

        private TbEMManager()
        {
        }

        public TbEMEntity GetModelByCache(int EMId)
        {
            string CacheKey = "TbEMEntityModel-" + EMId;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(EMId);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("EntityCacheMinutes");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (TbEMEntity)objModel;
        }



        public List<TbEMEntity> QueryEMByYear(int year)
        {
           return dal.QueryEMByYear(year);
        }
       

    }
}
